package com.cyx.controller;

import com.cyx.pojo.PageResult;
import com.cyx.pojo.Result;
import com.cyx.pojo.Student;
import com.cyx.pojo.StudentQueryParam;
import com.cyx.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RequestMapping("/students")
@RestController
public class StudentController {
    @Autowired
    private StudentService studentService;
    /**
     * 学生列表的分页查询
     */
    @GetMapping
    public Result page(StudentQueryParam studentQueryParam){
        log.info("学生列表的分页查询，参数：{}", studentQueryParam);
        PageResult<Student> pageResult = studentService.page(studentQueryParam);
        return Result.success(pageResult);
    }
    /**
     *  新增学生信息结果
     */
    @PostMapping
    public Result add(@RequestBody Student student){
        log.info("新增学生信息，参数：{}", student);
        studentService.addStudent(student);
        return Result.success();
    }
    /**
     * 根据ID查询学生信息
     *
     */
    @GetMapping("/{id}")
    public Result getInfoById(@PathVariable Integer id){
        log.info("根据学生id查询学生信息，id：{}", id);
        Student student = studentService.getInfoById(id);
        return Result.success(student);
    }
    /**
     * 修改学生信息
     *
     */
    @PutMapping
    public Result update(@RequestBody Student student){
        log.info("修改学生信息，参数：{}", student);
        studentService.updateStudent(student);
        return Result.success();
    }
    /**
     * 删除学生信息
     *
     */
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable List<Integer> ids){
        log.info("删除学生信息，参数：{}", ids);
        studentService.deleteStudentByIds(ids);
        return Result.success();
    }

    /**
     * 学生违纪处理
     *
     */
    @PutMapping("/violation/{id}/{score}")
    public Result violationStudent(@PathVariable Integer id,@PathVariable Short score){
        log.info("学生违纪处理，参数：id={},score={}", id, score);
        studentService.violationStudent(id, score);
        return Result.success();
    }


}
